<template>
	<view class="page">
		<!-- <v-tabs v-model="active" :tabs="tabs" :scroll="false" height="105upx" fontSize="32upx" activeColor="#369049" lineColor="#369049"></v-tabs> -->
		
		<view style="" v-for="(item, index) in orderList" :key="index">
			<view class="height25"></view>
			<view loadMore="over" class="orderList">
				<view 
					class="list-item"
					@click="itemClick(item.id)"
				>
					<view class="title">
						<view class="titleLeft cbczd">
							<image mode="scaleToFill" :src="imgUrl+'/shopImg/assets/images/order/cbdOrder.png'"/>
							<view class="text">{{item.orderType}}</view>
						</view>
						<view class="status status-l">{{item.statusName}}</view>
					</view>
					<view class="order-info">
						<view class="car-img">
							<image mode="aspectFit" :src="item.logo"></image>
						</view>
						<view class="car-text">
							<view class="car-name">{{item.brand + item.series + item.vehicle_type}}</view>
							<view class="order-no">订单号：{{item.order_no}}</view>
							<view class="time">{{item.createDate}}</view>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
	 getListOrderBySiteUserId,
	} from '@/service/chengyongche'
	import { imgUrl } from '@/service/config.js'
	export default {
		data() {
			return {
				orderList: [],
				list: [],
				tabs: [],
				active: '',
				imgUrl: imgUrl,
				status: '',
				userInfoData: '',
				header: '',
			}
		},
		onLoad(e) {
			console.log(e)
			uni.showLoading();
			this.isOrder = e.isOrder
			this.init();
			let userBizType = uni.getStorageSync('userBizType');
			let userInfoData = uni.getStorageSync('userInfo');
			let scUserInfo = uni.getStorageSync('scUserInfo');
			let header = {
				'content-type': 'application/x-www-form-urlencoded',
				'Authorization': userInfoData.token
			};
			this.userInfoData = userInfoData;
			this.header = header;
			this.scUserInfo = scUserInfo.data;
			this.active = 0
		},
		watch: {
			active (val) {
				this.active = val;
				let userInfoData = this.userInfoData;
				let header = this.header;
				let scUserInfo = this.scUserInfo;
				let biz_type = 7 // 默认购车贷
				// if(val == 1) biz_type = 8 // 租车贷
				const prams = {siteUserId: userInfoData.mobile, biz_type};
				this._getListOrderBySiteUserId(JSON.stringify(prams), header, val, 'active')
			}
		},
		methods: {
			init () {
				this.list = []
				this.tabs = [
					'购车贷',
					'租车贷'
				]
			},
			/**
			 * 点击列表触发事件
			 * @method itemClick
			 * @param {*} index
			 */
			itemClick(id) {
				const orderId = id;
				let _this = this;
				uni.setStorage({
					key: 'orderDate',
					data: {orderId},
					success: function() {
						uni.navigateTo({ url: '/pages/chengyongche/orderDetail/orderDetail'})
					}
				})
			},
			shuju(data,val){
				data.length == 0 ? uni.showToast({
					title: '暂无'+this.tabs[val]+'订单',
					mask: true,
					icon: 'none'
				}) : "";
			},
			//-------------------网络请求---------------------
			_getListOrderBySiteUserId(prams, header, index, tabsName) {
				getListOrderBySiteUserId(prams, header).then(res => {
					const data = res.data;
					if(data.resultCode != "0000") {
						uni.showModal({
							content: res.data.resultMsg,
							success: () => {
								uni.hideLoading();
							}
						});
					}else {
						this.orderList = data.data.orderList;
						this[tabsName] = index;
						uni.hideLoading();
					}
				}).catch(err => {
					uni.hideLoading();
				})
			},
		}
	}
</script>

<style>
	@import url("./orderList.css");
	
	uni-image {
		width: 100%;
		height: 100%;
	}
</style>
